import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import { BasicForm, FormSchema, useForm } from "@/components/Form";
import { processInstanceApi } from "@/api/bpm/task/processInstance";
import { message } from "antd";
import { useTranslation } from "react-i18next";
let id: String;
const index = (props: any) => {
	const { t } = useTranslation();
	const en_vi = "task.processInstance";
	const schemas: FormSchema[] = [
		{
			label: t(`${en_vi}.cancellation`),
			component: "InputTextArea",
			field: "reason"
		}
	];
	const [registerDrawer, { closeDrawer }] = useDrawerInner(props.register, data => {
		console.log(data);
		id = data.record.id;
		resetFields();
	});
	const [register, { validateFields, resetFields }] = useForm({
		schemas,
		labelWidth: 130,
		baseColProps: {
			span: 24
		}
	});
	const handleSubmit = async () => {
		let formValue = await validateFields();
		formValue = {
			...formValue,
			id
		};
		console.log(formValue);
		const res = await processInstanceApi.processInstanceCancelByStartUser(formValue);
		if (!res) return message.error(t(`${en_vi}.cancelFailed`));
		message.success(t(`${en_vi}.cancelSuccessfully`));
		closeDrawer();
	};
	return (
		<BasicDrawer title={t(`${en_vi}.cancelProcess`)} showFooter={true} {...props} register={registerDrawer} ok={handleSubmit}>
			<BasicForm register={register} labelWrap={true}></BasicForm>
		</BasicDrawer>
	);
};
export default index;
